<?php
namespace Home\Controller;
use Org\OAuth2\OAuth2;
use Think\Controller;

class OAuth2Controller extends Controller{
	
	protected $oauth2;
	
	function __construct(){
		parent::__construct();
		header("Content-type:text/html; charset=utf-8");
		$this->oauth2	= new OAuth2();
	}
	
	function authorize(){
		$selfParam['userid']	= 1001;
		$selfParam['passwd']	= md5("verylucky");
		
		if($_POST){
			$this->oauth2->finishClientAuthorization($_POST['accept'] == "Yep", $_POST, $selfParam);
		}
		
		$status	= $this->oauth2->verifyClient($_GET['client_id'], $_GET['secret']);
		if(!$status){
			echo "client_id或者secret错误";
			//header("Location:".$_GET['redirect_uri']);
			return false;
		}
		
		$oauthParam = $this->oauth2->getAuthorizeParams();
		
		$this->assign("oauthParam",$oauthParam);
		$this->display("authorize");
	}
	
	function token(){
		$this->oauth2->grantAccessToken();
	}
	
	function toUseApi(){
		
	}
	
}